package com.csy.user.controller.owner;

import com.csy.commons.core.controller.BaseController;
import com.csy.commons.core.domain.BaseResponse;
import com.csy.commons.core.page.PageResult;
import com.csy.user.entity.owner.domain.AjOwner;
import com.csy.user.entity.owner.domain.vo.AjOwnerRoomVo;
import com.csy.commons.vo.AjOwnerVo;
import com.csy.user.entity.owner.service.AjOwnerRoomService;
import com.csy.user.entity.owner.service.AjOwnerService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 业主控制类
 */
@RestController
@RequestMapping("/system/owner")
public class AjOwnerController extends BaseController {

    @Resource
    private AjOwnerService ajOwnerService;

    @Resource
    private AjOwnerRoomService ajOwnerRoomService;

    @GetMapping("/countOwner")
    public BaseResponse<Integer> countOwner(){
        int ownerNum = ajOwnerService.countOwner();
        return BaseResponse.success(ownerNum);

    }
    @GetMapping("/list")
    public PageResult list(AjOwnerVo ajOwnerVo){
        startPage();
        List<AjOwnerVo> list = ajOwnerService.selectOwnerList(ajOwnerVo);

        return getData(list);

    }
    @GetMapping("/getByName")
    public AjOwnerVo getOwnerByName(@RequestParam("ownerRealName")String ownerRealName){
        AjOwnerVo ownerVo = ajOwnerService.getByName(ownerRealName);
        return ownerVo;

    }
    @GetMapping("/{ownerId}")
    public BaseResponse<AjOwnerVo> getOwner(@PathVariable("ownerId")Long ownerId){
        return BaseResponse.success(ajOwnerService.getById(ownerId));
    }
    @PostMapping
    public BaseResponse<Integer> addOwner(@RequestBody AjOwner ajOwner){
        int row = ajOwnerService.add(ajOwner);
        return toAjax(row);
    }

    @PutMapping
    public BaseResponse<Integer> updateOwner(@RequestBody AjOwner ajOwner){
        int row = ajOwnerService.update(ajOwner);
        return toAjax(row);
    }

    @PutMapping("/unbind")
    public BaseResponse<Integer> unBindOwner(@RequestBody AjOwnerRoomVo ajOwnerRoomVo){
        System.out.println("ownerRoomId-----"+ajOwnerRoomVo.getOwnerRoomId());
        int row = ajOwnerRoomService.unBindOwner(ajOwnerRoomVo);
        return toAjax(row);
    }

    @DeleteMapping("/{ownerId}")
    public BaseResponse<Integer> ownerDel(@PathVariable("ownerId") Long ownerId){
        int row = ajOwnerRoomService.ownerDel(ownerId);
        return toAjax(row);

    }

}
